package com.cn.transfer.service.impl;

import com.cn.transfer.dao.AccountDao;
import com.cn.transfer.myanno.MyAutowired;
import com.cn.transfer.myanno.MyService1;
import com.cn.transfer.myanno.MyTransactional;
import com.cn.transfer.pojo.Account;
import com.cn.transfer.service.TransferService;
import com.cn.transfer.utils.ConnectionUtils;
import com.cn.transfer.utils.TransactionManager;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;


/**
 * @author pengg
 */
@MyService1("transferService")
public class TransferServiceImpl implements TransferService {

    // 最佳状态
    // @Autowired 按照类型注入 ,如果按照类型无法唯一锁定对象，可以结合@Qualifier指定具体的id
    /*@Autowired
    @Qualifier("accountDao")*/
    @MyAutowired("accountDao")
    private AccountDao accountDao;

    @Override
    @MyTransactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney() - money);
        to.setMoney(to.getMoney() + money);

        accountDao.updateAccountByCardNo(to);
        //int c = 1/0;
        accountDao.updateAccountByCardNo(from);
    }

}
